package com.eastfair.messagecenter.util;

import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.messagecenter.dto.InnerSendDTO;
import com.eastfair.messagecenter.dto.SmsSendDTO;
import com.eastfair.messagecenter.enumeration.ChannelType;
import com.eastfair.messagecenter.model.InnerContentModel;
import com.eastfair.messagecenter.model.SmsContentModel;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class InnerSendDtoUtil {
    /**
     * 内容属性名称
     */
    private String mapName = "content";

    /**
     * 发送站内信 组装实体
     *
     * @param bysinessType
     * @param userIds
     * @param content
     * @return
     */
    public static InnerSendDTO sendInnerDto(String bysinessType, Set<Long> userIds, String content) {
        //发送站内信
        InnerSendDTO innerSendDTO = new InnerSendDTO();
        innerSendDTO.setBusinessType(bysinessType);
        innerSendDTO.setChannelType(ChannelType.INNER_IM);
        innerSendDTO.setBusinessId(ContextUtil.getTrace());
        InnerContentModel innerContentModel = new InnerContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        innerContentModel.setContentMap(contentMap);
        innerSendDTO.setInnerContentModelList(Arrays.asList(innerContentModel));
        innerSendDTO.setSenUserIdList(userIds);
        return innerSendDTO;
    }

    /**
     * 发送站内信 组装实体
     *
     * @param bysinessType
     * @param userIds
     * @param content
     * @return
     */
    public static InnerSendDTO sendInnerDto(String bysinessType, Set<Long> userIds, String content, LocalDateTime predictSendTime) {
        //发送站内信
        InnerSendDTO innerSendDTO = new InnerSendDTO();
        innerSendDTO.setBusinessType(bysinessType);
        innerSendDTO.setChannelType(ChannelType.INNER_IM);
        innerSendDTO.setBusinessId(ContextUtil.getTrace());
        InnerContentModel innerContentModel = new InnerContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        innerContentModel.setContentMap(contentMap);
        innerSendDTO.setInnerContentModelList(Arrays.asList(innerContentModel));
        innerSendDTO.setSenUserIdList(userIds);
        if (predictSendTime == null) {
            innerSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            innerSendDTO.setPredictSendTime(predictSendTime);
            innerSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return innerSendDTO;
    }







    /**
     * 发送站内信 组装实体
     *
     * @param bysinessType
     * @param orgIds
     * @param content
     * @return
     */
    public static InnerSendDTO sendInnerDtoOfOrgid(String bysinessType, Set<Long> orgIds, String content, LocalDateTime predictSendTime) {
        //发送站内信
        InnerSendDTO innerSendDTO = new InnerSendDTO();
        innerSendDTO.setBusinessType(bysinessType);
        innerSendDTO.setChannelType(ChannelType.INNER_IM);
        innerSendDTO.setBusinessId(ContextUtil.getTrace());
        InnerContentModel innerContentModel = new InnerContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        innerContentModel.setContentMap(contentMap);
        innerSendDTO.setInnerContentModelList(Arrays.asList(innerContentModel));
        innerSendDTO.setOrgIdList(orgIds);
        if (predictSendTime == null) {
            innerSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            innerSendDTO.setPredictSendTime(predictSendTime);
            innerSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return innerSendDTO;
    }



    /**
     * 发送站内信 组装实体
     *
     * @param bysinessType
     * @param isSendAll
     * @param content
     * @return
     */
    public static InnerSendDTO sendInnerDto(String bysinessType, Boolean isSendAll, String content, LocalDateTime predictSendTime) {
        //发送站内信
        InnerSendDTO innerSendDTO = new InnerSendDTO();
        innerSendDTO.setBusinessType(bysinessType);
        innerSendDTO.setChannelType(ChannelType.INNER_IM);
        innerSendDTO.setBusinessId(ContextUtil.getTrace());
        InnerContentModel innerContentModel = new InnerContentModel();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("content", content);
        innerContentModel.setContentMap(contentMap);
        innerSendDTO.setInnerContentModelList(Arrays.asList(innerContentModel));
        innerSendDTO.setIsSendAll(isSendAll);
        if (predictSendTime == null) {
            innerSendDTO.setIsSendNow(BusinessConstant.YES);
        } else {
            innerSendDTO.setPredictSendTime(predictSendTime);
            innerSendDTO.setIsSendNow(BusinessConstant.NO);
        }
        return innerSendDTO;
    }
}
